using System.Reflection;
using NUnit.Framework;
using ContentRenderingApi;
using ContentRenderingApiSystemTest.Helper;
using ContentRenderingApi.Path;

namespace ContentRenderingApiSystemTest.TestFixture
{
    [TestFixture]
    public class RenderObserverTestFixture
    {
        [Test]
        public void CounterTest()
        {
            AbstractTemplate template = new EmbeddedResourceTemplate(
                Assembly.GetExecutingAssembly(),
                "ContentRenderingApiSystemTest.TestFixture.Input",
                "Observer");

            int counter = 0;

            template.TransformationConfiguration.AddObserverFunction(new PartialPath("CounterIncrementOne"), value => counter++);
            template.TransformationConfiguration.AddObserverFunction(new PartialPath("CounterIncrementTwo"), value => counter++);
            template.TransformationConfiguration.AddObserverFunction(new PartialPath("CounterIncrementThree"), value => counter++);
            template.TransformationConfiguration.AddFormattedOutputFunction(new PartialPath("CounterValueOne"), value => counter.ToString());
            template.TransformationConfiguration.AddFormattedOutputFunction(new PartialPath("CounterValueTwo"), value => counter.ToString());
            template.TransformationConfiguration.AddFormattedOutputFunction(new PartialPath("CounterValueThree"), value => counter.ToString());

            string output = template.Render();

            Assert.AreEqual(
                ResourceHelper.FetchString("ContentRenderingApiSystemTest.TestFixture.Output.Observer.txt"),
                output);
        }
    }
}
